package com.benjamin.common;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import android.content.Context;
import android.graphics.drawable.Drawable;

public class ImageUtils {

	public static Drawable getImage(Context ctx, String imgName)
			throws IOException {
		FileInputStream inputStream = null;
		Drawable drawable = null;

		try {
			try {

				// /data/data/package name/files
				inputStream = ctx.openFileInput(imgName);

				drawable = Drawable.createFromStream(inputStream, "");
			} finally {
				if (inputStream != null) {
					inputStream.close();
				}
			}
		} catch (IOException ioe) {
			android.util.Log.e("ImageUtils", ioe.getMessage(), ioe);
			throw ioe;
		}

		return drawable;
	}

	public static Drawable getImage(String strURL) throws IOException {
		InputStream inputStream = null;
		Drawable drawable = null;

		try {
			try {
				URL url = new URL(strURL);
				inputStream = url.openStream();

				drawable = Drawable.createFromStream(inputStream, "");

			} finally {
				if (inputStream != null) {
					inputStream.close();
				}
			}
		} catch (IOException ioe) {
			android.util.Log.e("ImageUtils", ioe.getMessage(), ioe);
			throw ioe;
		}

		return drawable;
	}
}
